package com.atguigu.Controller;

import com.atguigu.Serivce.ShoppingCartService;
import com.atguigu.Utils.R;
import com.atguigu.pojo.ShoppingCart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 有个bug：无法一次选择两种口味，若想修改前端和后端都要修改
     * @param cart
     * @return
     */
    @PostMapping("add")
    public R add(@RequestBody ShoppingCart cart) {
        return shoppingCartService.add(cart);
    }

    @GetMapping("list")
    public R list() {
        return shoppingCartService.listCart();
    }

    @PostMapping("sub")
    public R sub(@RequestBody ShoppingCart cart) {
        return shoppingCartService.sub(cart);
    }

    @DeleteMapping("clean")
    public R cleanCart() {
        return shoppingCartService.cleanCart();
    }
}
